<?php
	class ManagerModel extends Model
	{
		public $_validate =	array(
				array('name','/^[a-z]\w{2,}$/i','帐号格式错误'),
				array('password','6,12','密码长度必须在6-12位之间',Model::VALUE_VAILIDATE,'length'),
				array('repwd','require','确认密码必须'),
				array('repwd','password','确认密码不一致',self::EXISTS_VAILIDATE,'confirm'),
				array('name','','帐号已经存在',self::EXISTS_VAILIDATE,'unique',self::MODEL_INSERT),
				array('level','require','等级必须选择！'),
		);
		
		public $_auto =	array(
				array('password','md5',self::MODEL_BOTH,'function'),
				array('reg_time','time',self::MODEL_INSERT,'function'),
				array('password','chkEmpty',self::MODEL_UPDATE,'callback'),
		);
		
		
		public $_map = array(
				"pwd" => "password",
				);
		
		public function chkEmpty()
		{
			if(empty($_POST['pwd'])){
				$manager = $this->field('password')->where('id = '.$_POST['id'])->find();
				return $manager['password'];
			}else{
				return md5($_POST['pwd']);
			}
				
		}
		
	}
?>